package com.migo.log;

import com.migo.utils.HttpClientUtils;
import com.migo.utils.JsonUtils;
import com.migo.utils.KafkaUtil;
import kafka.javaapi.producer.Producer;

public class SystemLogRunnable implements Runnable {
    protected SystemLog systemLog;
    private Producer<String, String> producer;

    public SystemLog getSystemLog() {
        return systemLog;
    }

    public void setSystemLog(SystemLog systemLog) {
        this.systemLog = systemLog;
    }

    public SystemLogRunnable(SystemLog systemLog) {
        this.systemLog = systemLog;
        this.producer = KafkaUtil.createProducer();
    }

    public void SystemLogProducer(SystemLog systemLog) {
        try {
            String topic = "APP2.0";
            String json = JsonUtils.getJSONString(systemLog);
            // 线上日志业务日志收集：nginx+4*torando（8081/8082/8083/8084） http://47.90.104.43:8080/saveAppLog
            // 测试业务日志收集：114.215.28.4 http://127.0.0.1:6666/saveAppLog
            // 海外内测测试业务日志收集：114.215.28.4 http://127.0.0.1:8086/saveAppLog
//            HttpClientUtils.post("http://127.0.0.1:6666/saveAppLog",json);
//            KafkaUtil.sendData(producer,topic,systemLog.getLogId(),json);
        } catch (Exception e) {

        }
    }

    @Override
    public void run() {
        SystemLogProducer(systemLog);
    }
}
